Conditions | 1 |
Paths | 2 |
Total Lines | 62 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var spauth = require('node-sp-auth'); |
||
10 | .then(function (data) { |
||
11 | var internalQueryStructureGeneric = MyCustomFunctions.internalQueryStructureArray(0); |
||
12 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'Lists', data)).then(function (responseList) { |
||
13 | if (Object.keys(responseList.d.results).length > 0) { |
||
14 | var wStreamListViews = MyCustomFunctions.createOutputFileWithHeader({'filePath': config.General.PathForExtracts, 'fileName': config.General.MetaDataFileName.Views, 'fileHeader': '"List Name"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Views).join('"' + config.General.ListSeparator + '"')}, fs); |
||
15 | var dataListLight = []; |
||
16 | var counter = 0; |
||
17 | responseList.d.results.forEach(function (itemList) { |
||
18 | dataListLight[counter] = MyCustomFunctions.buildCurrentListAttributeValues(config.SharePoint.MetaDataOutput.Lists, itemList); |
||
19 | counter++; |
||
20 | }); |
||
21 | var wStreamList = MyCustomFunctions.createOutputFileWithHeader({'filePath': config.General.PathForExtracts, 'fileName': config.General.MetaDataFileName.Lists, 'fileHeader': '"' + Object.keys(dataListLight[0]).join('"' + config.General.ListSeparator + '"')}, fs); |
||
22 | var wStreamListFields = MyCustomFunctions.createOutputFileWithHeader({'filePath': config.General.PathForExtracts, 'fileName': config.General.MetaDataFileName.Fields, 'fileHeader': '"List"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.Fields).join('"' + config.General.ListSeparator + '"')}, fs); |
||
23 | dataListLight.forEach(function (crtListParameters) { // parse each List |
||
24 | if (MyCustomFunctions.decideBlackListWhiteList(!crtListParameters.Hidden, config.SharePoint.Filters.Lists.NotHidden.BlackList, config.SharePoint.Filters.Lists.Hidden.WhiteList, crtListParameters.Title)) { // check current List against configured BlackList and WhiteList besides considering user defined Lists |
||
25 | wStreamList.write('"' + Object.keys(crtListParameters).map(function (x) { // records detail of current List |
||
26 | return crtListParameters[x]; |
||
27 | }).join('"' + config.General.ListSeparator + '"') + '"\n'); |
||
28 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Fields', data)).then(function (responseField) { // Dynamically detect structure of the list, extracting the Field names and their text to display |
||
29 | if (Object.keys(responseField.d.results).length > 0) { |
||
30 | var fieldAttributes = []; |
||
31 | responseField.d.results.forEach(function (itemField) { |
||
32 | if (MyCustomFunctions.decideBlackListWhiteList(itemField.CanBeDeleted, config.SharePoint.Filters.Fields.CanBeDeleted.BlackList, config.SharePoint.Filters.Fields.CannotBeDeleted.WhiteList, itemField.InternalName) || (config.SharePoint.Filters.Lists.Hidden.WhiteList.indexOf(crtListParameters.Title) > -1)) { // check current Field against configured BlackList and WhiteList besides considering user defined Fields || for certain Lists all existing fields should be retrieved |
||
33 | fieldAttributes[itemField.Title] = {'Technical Name': itemField.StaticName, 'Type': itemField.TypeAsString}; |
||
34 | wStreamListFields.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.Fields, itemField).join(config.General.ListSeparator) + '\n'); // fields of current List |
||
35 | } |
||
36 | }); |
||
37 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, MyCustomFunctions.internalQueryStructureArray(crtListParameters.Records), crtListParameters.Title, 'Items', data)).then(function (responseListRecord) { // Get the actual values from current list |
||
38 | MyCustomFunctions.manageRequestIntoCSVfile({'filePath': config.General.PathForExtracts, 'fileName': crtListParameters.Title, 'ListSeparator': config.General.ListSeparator}, crtListParameters, responseListRecord, fieldAttributes, fs); |
||
39 | }); |
||
40 | } |
||
41 | }); |
||
42 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtListParameters.Title, 'Views', data)).then(function (responseViews) { |
||
43 | if (Object.keys(responseViews.d.results).length > 0) { |
||
44 | responseViews.d.results.forEach(function (crtView) { |
||
45 | wStreamListViews.write('"' + crtListParameters.Title + '"' + config.General.ListSeparator + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.Views, crtView).join(config.General.ListSeparator) + '\n'); // writing current Views record values |
||
46 | }); |
||
47 | } |
||
48 | }); |
||
49 | } |
||
50 | }); |
||
51 | wStreamList.end(); |
||
52 | } |
||
53 | }); |
||
54 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, '', 'SiteGroups', data)).then(function (responseSiteGroups) { |
||
55 | if (Object.keys(responseSiteGroups.d.results).length > 0) { |
||
56 | var wStreamGroups = MyCustomFunctions.createOutputFileWithHeader({'filePath': config.General.PathForExtracts, 'fileName': config.General.MetaDataFileName.SiteGroups, 'fileHeader': '"' + Object.keys(config.SharePoint.MetaDataOutput.SiteGroups).join('"' + config.General.ListSeparator + '"')}, fs); |
||
57 | var wStreamGroupMembers = MyCustomFunctions.createOutputFileWithHeader({'filePath': config.General.PathForExtracts, 'fileName': config.General.MetaDataFileName.SiteGroupMembers, 'fileHeader': '"Group"' + config.General.ListSeparator + '"' + Object.keys(config.SharePoint.MetaDataOutput.SiteGroupMembers).join('"' + config.General.ListSeparator + '"')}, fs); |
||
58 | responseSiteGroups.d.results.forEach(function (crtItemGroup) { |
||
59 | wStreamGroups.write(MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.SiteGroups, crtItemGroup).join(config.General.ListSeparator) + '\n'); // writing current record values |
||
60 | request.get(MyCustomFunctions.buildRequestQuery(targetSharePoint.URL, internalQueryStructureGeneric, crtItemGroup.Id, 'GroupMembers', data)).then(function (responseMembers) { |
||
61 | if (Object.keys(responseMembers.d.results).length > 0) { |
||
62 | responseMembers.d.results.forEach(function (crtItemGroupMember) { |
||
63 | wStreamGroupMembers.write('"' + crtItemGroup.Title + '"' + config.General.ListSeparator + MyCustomFunctions.buildCurrentRecordValues(config.SharePoint.MetaDataOutput.SiteGroupMembers, crtItemGroupMember).join(config.General.ListSeparator) + '\n'); // writing current record values |
||
64 | }); |
||
65 | } |
||
66 | }); |
||
67 | }); |
||
68 | wStreamGroups.end(); |
||
69 | } |
||
70 | }); |
||
71 | }); |
||
72 |